<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
    <title>车辆保险查询审核</title>
    <style>
        /* 样式表 */
        table {
            border-collapse: collapse;
            width: 100%;
        }
        th, td {
            padding: 8px;
            text-align: center;
            border-bottom: 1px solid #ddd;
        }
        th {
            background-color: #f2f2f2;
        }
        input[type="text"] {
            padding: 6px;
            border: 1px solid #ccc;
            border-radius: 4px;
            box-sizing: border-box;
            width: 200px;
        }
        button {
            background-color: #4CB2F6;
            color: white;
            padding: 8px 16px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        button:hover {
            background-color: #0369BF;
        }
        
        .pagination {
        	position:absolute;
        	margin:20px;
        	right:0;
        	bottom:0;
            display: inline-block;
            margin-top: 16px;
        }
        .pagination a {
            color: black;
            float: left;
            padding: 8px 16px;
            text-decoration: none;
            border: 1px solid #ddd;
            margin: 0 4px;
        }
        .pagination a.active {
            background-color: #4CB2F6;
            color: white;
        }
        .pagination a:hover:not(.active) {
            background-color: #ddd;
        }
        .btn {
        	color: #1890ff;
        	padding: 8px 16px;
        	border: none;
        	border-radius: 4px;
        	cursor: pointer;
        	text-decoration: none;
    	}
    	.btn:hover{
    		text-decoration: underline;
    	}
    	#header2 {
    	width:115%;
			height: 40px;
			background: #F6F6F6;
		}
    </style>
</head>
<body>
<%
    	String num = request.getParameter("num");
    	String violation = request.getParameter("violation");
    	String dispose = request.getParameter("dispose1");
    	String sql = "SELECT * FROM TrafficViolation WHERE 1=1";
    	Connection conn=null;
	%>
	<div id="header2">
		<img src="img/申请用车.png" alt="Big Boat" width="30" height="30"
			style="vertical-align: middle;"> 车辆违章 > 违章详情
	</div>
   <form method="post">
    <div style="height:50px;background-color:#DFF8FF;position:relative;display:flex;align-items:center;">
    <div style="flex:1;display:flex;align-items:center;">
        <label for="num">车牌号：</label>
        <input type="text" id="num" name="num" style="margin-right:20px;">
        <label for="dispose1">是否处理：</label>
        <input type="text" id="dispose1" name="dispose1" style="margin-right:20px;" list="condition">
        <datalist id="condition">
			<option>未处理</option>			
			<option>已处理</option>
		</datalist>
        <label for="violation" >违章类别：</label>
        <input type="text" id="violation" name="violation" list="violation1">
        <datalist id="violation1">
                    <option>闯红灯</option>
                    <option>超速</option>
                    <option>超载</option>
                    <option>违章停车</option>
                    <option>无证驾驶</option>
                    <option>违章超车</option>
                    <option>疲劳驾驶</option>
                    <option>酒后驾驶</option>
                    <option>未系安全带</option>
                    <option>车祸</option>
        </datalist>
    </div>
    <div style="display:flex;align-items:center;">
        <button type="submit">查询</button>
    </div>
	</div>
	</form>
	<% 
   			if (num != null && !num.isEmpty()) {
        		sql += " AND license_plate = '" + num+"'";
    		}
    		if (violation != null && !violation.isEmpty()) {
    			sql += " AND violation_type = '" + violation+"'";
    		}
    		if (dispose != null && !dispose.isEmpty()) {
    			sql += " AND dispose = '" + dispose+"'";
    		}
    		try{
				Class.forName("org.h2.Driver");//加载驱动
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
				return;
			}
    		try {
        		conn = DriverManager.getConnection("jdbc:h2:~/test", "sa", "");
        		Statement stmt = conn.createStatement();
        		ResultSet rs = stmt.executeQuery(sql);   		
%>
    <table>
        <thead>
            <tr>
                <th>序号</th>
                <th>车牌号码</th>
                <th>违章日期</th>
                <th>违章类别</th>
                <th>驾驶员</th>
                <th>扣分</th>
                <th>罚款</th>
                <th>是否处理</th>
                <th>处理时间</th>
                <th>违章地点</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
           <% while(rs!=null && rs.next()){ %>
				<tr>
					<td><%=rs.getInt("id") %></td>
                	<td><%=rs.getString("license_plate") %></td>
                	<td><%=rs.getString("accident_time") %></td>
                	<td><%=rs.getString("violation_type") %></td>
                	<td><%=rs.getString("reporter") %></td>
                	<td><%=rs.getString("penalty_points") %></td>
                	<td><%=rs.getString("compensation") %></td>
                	<td><%=rs.getString("dispose") %></td>
                	<td><%=rs.getString("dispose_time") %></td>
                	<td><%=rs.getString("accident_location") %></td>
                	<%String queryURL="D-Details_Violation_look.jsp?action=1&id="+rs.getInt("id"); %>
                	<%String editURL="D-Details_Violation_edit.jsp?action=2&id="+rs.getInt("id"); %>
					<%String deleteURL="D-jdbc-Details_Violation_delete.jsp?action=2&id="+rs.getInt("id"); %>
                <td>
                    <a class="btn" href=<%=queryURL %>>查看</a>
                    <a class="btn" href=<%=editURL %>>编辑</a>
					<a class="btn" id="delete_<%=rs.getInt("id") %>" style="color:red" href=<%=deleteURL %> >删除</a>
                </td>
            </tr>
            <% } %>
        </tbody>
    </table>
    <div class="pagination">
        <a href="#">« 上一页</a>
        <a href="#" class="active">1</a>
        <a href="#">2</a>
        <a href="#">3</a>
        <a href="#">下一页 »</a>
    </div>
    <%
        rs.close();
        stmt.close();
      //关闭表达式对象				
    	conn.close();			
    	
    } catch (SQLException e) {
    	e.printStackTrace();
    } finally{
    	//防止数据库未正常关闭
    	try{
    		if (conn!=null && (!conn.isClosed())){
    			conn.close();
    		}
    	}catch(SQLException e){
    		e.printStackTrace();
    	}
    }
%>
</body>
</html>